/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import com.sun.lwuit.Form;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.Command;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BorderLayout;

/**
 *
 * @author Kvest
 */
public class MessageForm extends Form implements ActionListener
{
    public static final int EMPTY_ID = 0;
    public static final int BACK_ID = 2;

    private Command back;

    private FormAction listener;

    private TextArea text;

    public MessageForm(FormAction listener)
    {
        super("Сообщение");
        this.listener = listener;

        init();
    }

    private void init()
    {
        setLayout(new BorderLayout());

        addCommandListener(this);

        addCommand(new Command("", EMPTY_ID));
        back = new Command("Назад",BACK_ID);
        addCommand(back);

        text = new TextArea("", 1, 30);
        text.setAlignment(TextArea.LEFT);
        text.setEditable(false);

        addComponent(BorderLayout.NORTH, text);
    }

    public void actionPerformed(ActionEvent evt)
    {
        if (listener != null)
        {
            listener.commandAction(evt.getCommand().getId());
        }
    }

    public void setText(String value)
    {
        text.setText(value);
    }
}
